package com.example.pc.mytestapplication.adapter;

import android.content.Context;
import android.databinding.DataBindingUtil;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.example.pc.mytestapplication.data.MainData;
import com.example.pc.mytestapplication.R;
import com.example.pc.mytestapplication.databinding.ItemLvMainBinding;
import com.example.pc.mytestapplication.util.YZLog;

import java.util.List;

/**
 * Created by lxg on 2018/1/24.
 */

public class AdapterMain extends BaseAdapter {
    private Context context;
    private List<MainData> list;
    private ItemLvMainBinding inflate;

    public AdapterMain(Context context, List<MainData> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public void notifyDataSetChanged() {
        YZLog.i("数据刷新");
        super.notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        if (view == null) {
            inflate = DataBindingUtil.inflate(LayoutInflater.from(context), R.layout.item_lv_main, viewGroup, false);
            view = inflate.getRoot();
            view.setTag(inflate);
        } else {
            inflate = (ItemLvMainBinding) view.getTag();
        }
        inflate.setData(list.get(i));
        inflate.setAdapter(this);
        inflate.btItemMain.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

            }
        });
        return view;
    }
}
